/*
 * @Author: huangtianyang 916072572@qq.com
 * @Date: 2023-11-24 09:49:50
 * @LastEditors: huangtianyang
 * @LastEditTime: 2024-05-11 16:43:11
 * @FilePath: \driving-training-admin\src\apis\upload\index.ts
 */
import axios from '../../axios/index'

/**
 *
 * @param fileStr  base64的文件
 * @param dirType  类型为：class|school|coach|train_site 不传默认进入other
 * @returns
 */
export const uploadByBase64 = (fileStr: string, dirType?: string) => {
    return axios({
        method: 'post',
        url: '/api/system/file/manage/upload/base64',
        data: { fileStr, dirType }
    })
}

/**
 *
 * @param file     file的文件
 * @param dirType  类型为：class|school|coach|train_site 不传默认进入other
 * @returns
 */
export const uploadByFile = (file: File, dirType: string) => {
    const fileFormData = new FormData()
    fileFormData.append('file', file)
    fileFormData.append('dirType', dirType)
    return axios({
        method: 'post',
        url: '/api/system/file/manage/upload',
        data: fileFormData
    })
}

export const fileUrl = (key: string) => {
    return axios({
        method: 'get',
        url: '/api/system/file/manage/url',
        params: { key }
    })
}

export const downloadTemplate = () => {
    return axios({
        method: 'get',
        url: '/api/system/template/download/{fileName}'
    })
}

/**
 * 公开文件 文件上传 base64格式
 * @param fileStr
 * @param dirType
 * @returns
 */
export const uploadPublicByBase64 = (fileStr: string, dirType?: string) => {
    return axios({
        method: 'post',
        url: '/api/system/file/manage/upload/base64/public',
        data: { fileStr, dirType }
    })
}

/**
 * 公开文件 文件上传 file格式
 * @param file
 * @param dirType
 * @returns
 */
export const uploadPublicByFile = (file: File, dirType: string = '') => {
    const fileFormData = new FormData()
    fileFormData.append('file', file)
    fileFormData.append('dirType', dirType)
    return axios({
        method: 'post',
        url: '/api/system/file/manage/upload/public',
        data: fileFormData
    })
}
